package com.onefinger.manager.managers
{
	import com.onefinger.manager.views.model.BaseCRUDModel;
	import com.onefinger.manager.views.model.ItemCRUDModel;
	import com.onefinger.manager.vos.Category;
	import com.onefinger.manager.vos.Item;
	
	import flash.events.Event;
	import flash.events.EventDispatcher;
	import flash.events.IEventDispatcher;
	
	import mx.collections.ArrayCollection;
	
	public class ItemManager extends BaseManager
	{
		//--------------------------------------------------------------------
		//    Public Setters and Getters
		//--------------------------------------------------------------------
		
		
		//.................Items......................
		private var _items:ArrayCollection=new ArrayCollection();
		
		[Bindable(event="changeItems")]	
		public function get items():ArrayCollection
		{
			return _items;
		}
		
		public function setItems(value:ArrayCollection):void
		{
			_items = value;
			dispatchEvent( new Event( "changeItems" ) );
		}
		
		public function addItem(value:Item):void
		{
			_items.addItem(value);
			dispatchEvent( new Event( "changeItems" ) );
		}
		//.................Item......................
		private var _item:Item = new Item();
		
		[Bindable(event="changeItem")]
		public function get item():Item
		{
			return _item;
		}
		public function setItem(value:Item):void
		{
			_item = value;
			dispatchEvent( new Event( "changeItem" ) );
		}
		public function selectItem(value:Item):void
		{
			_item = value;
			dispatchEvent( new Event( "changeItem" ) );
		}
		//................._filterSubcategories......................
		private var _filterSubcategories:ArrayCollection;
		
		[Bindable(event="changeFilterSubcategories")]
		public function get filterSubcategories():ArrayCollection
		{
			return _filterSubcategories;
		}
		public function setFilterSubcategories(value:ArrayCollection):void
		{
			_filterSubcategories =new ArrayCollection( value.source );
			dispatchEvent( new Event( "changeFilterSubcategories" ) );
		}
		
		private var _selectedCategory:Category;
		[Bindable(event="changeSelectedCategory")]	
		public function get selectedCategory():Category
		{
			return _selectedCategory;
		}
		public function set selectedCategory(value:Category):void
		{
			_selectedCategory = value;
			dispatchEvent(new Event("changeSelectedCategory"));
		}
		
		public function setSelectedCategory(value:Item):void
		{
			var item:Item = value as Item;
			if(item!=null && item.subcategory!=null && item.subcategory.category!=null ){
			_selectedCategory =  item.subcategory.category;
			}
			dispatchEvent(new Event("changeSelectedCategory"));
		}
	}
}